<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title th:text="'码匠社区 - '+${question.title}"></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script src="/static/bootstrap-3.3.7/js/jquery.min.js"></script>
    <script src="/static/js/axios/axios.js"></script>
    <script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <link rel="icon" href="/static/img/favicon.ico" type="image/x-icon"/>
    <link rel="bookmark" href="/static/img/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/static/css/majiang.css">
    <script src="/static/js/majiang.js"></script>

    <link rel="stylesheet" href="/static/editor.md/css/editormd.min.css"/>
    <link rel="stylesheet" href="/static/editor.md/css/editormd.preview.css"/>
    <script src="/static/editor.md/editormd.min.js"></script>
    <script src="/static/editor.md/lib/marked.min.js"></script>
    <script src="/static/editor.md/lib/prettify.min.js"></script>
    <script src="/static/editor.md/lib/flowchart.min.js"></script>
    <script src="/static/editor.md/lib/marked.min.js"></script>
    <script src="/static/editor.md/lib/sequence-diagram.min.js"></script>
    <script src="/static/editor.md/lib/underscore.min.js"></script>

    <style>
        .menu {
            color: #999;
            margin-top: 10px;
        }

        .menu .icon {
            margin-right: 6px;
            font-size: 15px;
            cursor: pointer;
        }

        .menu .icon:hover {
            color: #499ef3;
        }

        .tag {
            font-size: 14px;
            margin-right: 10px;
        }

        .reply {
            padding: 10px 10px;
        }

        .reply-btn {
            margin-top: 6px;
        }

        .reply-box {
            margin-bottom: 36px;
        }

        .question-related {
            line-height: 20px;
            font-size: 12px;
            margin-left: 0;
            list-style: none;
            text-decoration: none;
            padding-left: 0;
        }

        #hitokoto {
            margin: auto;
            font-family: "仿宋", sans-serif;
        }

        #hitokoto_content {
            font-size: large;
            text-indent: 2em;
        }

        #hitokoto_from {
            text-align: right;
            font-size: medium;
        }
    </style>
</head>
<body>
<div th:insert="navigation :: nav"></div>
<div class="container-fluid main" id="profile">
    <div class="row">
        <div class="col-lg-9 col-md-12 col-sm-12 col-xs-12">
            <!--正文-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4 th:text="${question.title}" style="margin-top: 25px"></h4>
                <span class="text-desc">
                        作者：<span th:text="${question.user.name}"></span>&nbsp;
                        发布时间：<span th:text="${#dates.format(question.gmtCreated,'yyyy-MM-dd HH:mm')}"></span>&nbsp;
                        阅读数：<span th:text="${question.viewCount}"></span>
                </span>
                <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
                <!--内容 -->
                <div th:text="${question.description}" style="display: none" id="question_content"></div>
                <div id="viewer" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <textarea style="display:none;"></textarea>
                </div>
                <input type="hidden" name="parentId" id="questionId" th:value="${question.id}"/>
                <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>

                <!--标签-->
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <span class="label label-info tag" th:each="tag : ${question.tag.split(',')}">
                        <span class="glyphicon glyphicon-tag" aria-hidden="true"></span>
                        <span th:text="${tag}"></span>
                    </span>
                </div>
                <!--编辑-->
                <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <a th:href="@{'/publish/'+${question.id}}" class="menu"
                       th:if="${session.user!=null && session.user.id==question.creator}">
                        <span class="glyphicon glyphicon-pencil" aria-hidden="true">编辑</span>
                    </a>
                </div>
            </div>
            <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
            <!--回复-->
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-left: 0px;font-size: medium">
                <span th:text="${question.commentCount}"></span>个回复
            </div>
            <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <ul class="list-group" th:each="comment:${comments}">
                    <li class="list-group-item">
                        <div class="media">
                            <div class="media-left">
                                <img class="media-object img-rounded" th:src="${comment.user.avatarUrl}"/>
                            </div>
                            <div class="media-body" style="padding-top: 10px">
                                <h6 class="media-heading">
                                    <span th:text="${comment.user.name}"></span>
                                </h6>
                                <div th:text="${comment.content}"></div>
                                <div class="menu">
                                    <a role="button" href="#" style="margin-right: 15px">
                                        <span class="glyphicon glyphicon-thumbs-up icon" aria-hidden="true"></span>
                                        <span th:text="${comment.likeCount}"></span>
                                    </a>
                                    <a role="button" data-toggle="collapse"
                                       th:href="'#comment_'+${comment.id}" aria-expanded="false"
                                       aria-controls="collapseExample" th:data-id="${comment.id}" onclick="reply(this)">
                                        <span class="glyphicon glyphicon-comment icon" aria-hidden="true"></span>
                                        <span th:text="${comment.commentCount}"></span>
                                    </a>
                                    <span class="pull-right"
                                          th:text="${#dates.format(comment.gmtCreated,'yyyy-MM-dd')}"></span>
                                </div>
                            </div>
                            <!--二级评论-->
                            <div class="collapse well reply" th:id="'comment_'+${comment.id}">
                                <ul class="list-group" th:id="'reply-'+${comment.id}">

                                </ul>
                                <div th:id="${'comment-'+comment.id}" class="reply-box">
                                    <div>
                                        <input type="text" class="form-control" placeholder="评论一下……"
                                               th:id="${'input-'+comment.id}">
                                        <button type="button" class="btn btn-success pull-right reply-btn"
                                                onclick="comment(this)"
                                                th:data-id="${comment.id}">评论
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </li>
                </ul>
            </div>
            <!--回复框-->
            <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" id="comment_section" th:if="${session.user != null}">
                <div class="media">
                    <div class="media-left">
                        <img class="media-object img-rounded"
                             th:src="${session.user.avatarUrl}"
                             th:alt="${session.user.name}">
                    </div>
                    <div class="media-body" style="padding-top: 10px">
                        <h6 class="media-heading">
                            <span th:text="${session.user.name}"></span>
                        </h6>
                    </div>
                </div>
                <textarea class="form-control" rows="6" style="margin: 10px 0" id="commentContent"></textarea>
                <button type="button" class="btn btn-success" style="float: right;margin-bottom: 10px" id="commentBtn">
                    回复
                </button>
            </div>
        </div>

        <!--右半部分-->
        <div class="col-lg-3 col-md-12 col-sm-12 col-xs-12">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4>发起人</h4>
                <div class="media">
                    <div class="media-left">
                        <img class="media-object img-circle"
                             th:src="${question.user.avatarUrl}"
                             th:alt="${question.user.name}">
                    </div>
                    <input type="hidden" name="parentId" id="parentId" th:value="${question.id}"/>
                    <div class="media-body" style="padding-top: 10px">
                        <h6 class="media-heading">
                            <span th:text="${question.user.name}"></span>
                        </h6>
                    </div>
                </div>
            </div>
            <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
            <div id="hitokoto">
                <p id="hitokoto_content"></p>
                <p id="hitokoto_from"></p>
            </div>
            <!--相关问题-->
            <hr class="divider col-lg-12 col-md-12 col-sm-12 col-xs-12"/>
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <h4>相关问题</h4>
                <ul th:each="relate:${question.relatedQuestions}" class="question-related">
                    <li><a th:href="'/question/'+${relate.id}" th:text="${relate.title}"></a></li>
                </ul>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        document.getElementById("commentBtn").addEventListener("click", post);
    });
    $(function () {
        let content = $("#question_content").html();
        var testView = editormd.markdownToHTML("viewer", {
            width: '100%',
            markdown: content,
            // 流程图
            flowChart: true,
            // 时序图
            sequenceDiagram: true,

            // 图片上传
            // imageUpload: true,
            // imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
            // imageUploadURL: "/file/upload",

            // html
            htmlDecode: true, // Decode all html tags & attributes
            atLink: false,    // disable @link
            emailLink: false,    // disable email address auto link
            preview: true,
            watch: true,
            editor: true,
            path: "/static/editor.md/lib/"
        });
    });
</script>
<div th:insert="footer :: foot"></div>
</body>
</html>